#---------------------------------
# Name: Chris Spooner
# Project Madlibs.py
# Period: 1
# Start Date: 9/18/2013
# Last Revision Date: 9/18/2013
# Version: 1.0.0
#----------------------------
import os

swearList = ["dumb"
            "slut",
            "cunt",
            "whore",
            "stupid"]
 

bgColor = '0'
txtColor = 'F'

def getMenuOption(maxOptions):
    option = ""
    goodOption = False
    while not goodOption:
        option = raw_input("Enter a number or S or Q> ")
        option = option.upper()
        if option == 'S':
            goodOption = True
        elif option == 'Q' :
            goodOption = True
        elif option == "":
            pass
        else:
            isNum = True
            for character in option:
                if character not in "0123456789":
                    isNum = False
            if isNum:
                if int(option) <= 0:
                    isNum = False
                elif int(option) > maxOptions:
                    isNum = False
            if isNum:
                goodOption = True
            else:
                print "Please type a song!"
        if not goodOption:
            print "Invalid Choice, please try again. "
    return option

def menu():
    raw_input("press enter to continue.")
    raw_input("press enter again..")
    raw_input("again..")
    raw_input("sorry.. again")
    raw_input("yes again!")
    raw_input("almost there!!")
    raw_input("just a few more..")
    raw_input("finally.")
    raw_input("press enter to continue.")
    raw_input("OK, are you ready yet?")
    raw_input("Error, Your computer is on overload and is about to crash. Please hit enter to exit this program.")
    print "Welcome to Madlibs are you ready to put your mind to the test?"
    print "Select an Option:"
    print " [1] The Game"
    print " [2] The majestic animal"
    print " [S] Settings"
    print " [Q] Quit"
    option = getMenuOption(2)
    return option

def getWord(prompt):
    word = ""
    goodWord = False
    while not goodWord:
        word = raw_input(prompt)
        if word.lower() not in swearList:
            goodWord = True
        else:
            print "How Rude. Try again or you will be kicked!"
        if not goodWord:
            print "Please try again."
    return word

def getNumber(prompt, min = "", max = ""):
        num = ""
        goodNumber = False
        while not goodNumber:
            num = raw_input(prompt)
            isNum = True
            for digit in num:
                if digit not in ".0123456789":
                    isNum = False
            if isNum:
                if min != "":
                    if float(num) < min:
                        isNum = False
                if max != "":
                    if float(num) > max:
                        isNum = False
            if isNum:
                goodNumber = True
            else:
                print "Please enter a valid number"
        return num
                    
def getColor(prompt):
    colors = ["black",
              "blue",
              "green",
              "bright white",
              "light red",
              "red"]
    opt = ""
    goodColor = False
    while not goodColor:
        opt = raw_input(prompt)
        if opt.lower() in colors:
            goodColor = True
    if opt == "black":
        color = '0'
    elif opt == 'blue':
        color = '1'
    elif opt == 'green':
        color = '2'
    elif opt == 'bright white':
        color = 'F'
    elif opt == 'light red':
        color = 'C'
    elif opt == 'red':
        color = '4'
    return color
        
            
                    
def story1():
    place1 = getWord("Enter a place: ")
    place2 = getWord("Enter a place: ")
    male_name1 = getWord("Enter a male name: ")
    male_name2 = getWord("Enter a male name: ")
    object = getWord("Enter a object: ")
    name3 = getWord("Enter a name: ")
    videogame = getWord("Enter a game:")
    song = getWord("Enter a song:")
    
    boardGame = getWord("Enter the name of a board game: ")
    story = "It was warm in  "
    story += place1 + ". "
    story += " We were playing "
    story += boardGame + ", "
    story += male_name1 
    story += " was losing so he through the game. Then "
    story +=  male_name2 
    story += " hit "
    story +=  male_name1  
    story += " with a "
    story +=  object  
    story +=  male_name2  
    story += " If you weren't such a sore loser I wouldn't have hit you with a "
    story += object 
    story += " Its just a game. "
    story += name3
    story += " said, maybe we should play a different game or do something different. "
    story += male_name1
    story += " what do you suggest? "
    story += name3
    story += " what about we play "
    story += videogame
    story += " and listen to "
    story += song
    story += "."
    print story
    

def story2():
    name = getWord("Enter a name: ")
    age = getNumber("Enter a number: ", 0)
    animal1 = getword("Enter a animal: ")
    story = "one day I was riding my "
    aniaml1 += animal
    story += " named "
    story += name + ". "
    story += " is "
    story += age + " "
    story += " years old. "
    story += " My friend was also riding his pet which is a "
    animal2 += animal
    story += " its name is " 
    name2 +=  name 
    
    story+= "."
    
    
    print story
    
def story3():
    place1 = getWord("Enter a place: ")
    song = getWord("Enter the name of a song: ")
    story = ""
    story += place1 + ". "
    story += " "
    story += song + ","
    story += ""
    print story

def settings():
    txtColor = getColor("Enter Text Color: ")
    bgColor = getColor("Enter Backgound Color: ")
    if txtColor != bgColor:
        os.system("color " + bgColor + txtColor)
    
def run():
    choice = ""
    while choice != 'Q':
        choice = menu()
        if choice == '1':
            story1()
        elif choice == '2':
            story2()
        elif choice == 'S':
            settings()
        elif choice == 'Q':
            print " Goodbye"
            os.system("color " + bgColor + txtColor)
            raw_input("Press enter to exit")
        else:
            print "Something terrible has happened...go yell at the programmer"
    
run() 